/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAOpeningHours.m
//  redia-bapps-ios
//
//  Created by Mads Darø Kristensen on 10/7/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BAOpeningHoursLibrary.h"
#import "JSONEncodingHelperMethods.h"

@implementation BAOpeningHoursLibrary

+ (id)objectWithJSONObject:(NSDictionary *)jsonObj
{
    BAOpeningHoursLibrary *obj = [[BAOpeningHoursLibrary alloc] init];
    
    obj.phone = [JSONEncodingHelperMethods parseStringWithKey:@"phone" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.phone);
    obj.fax = [JSONEncodingHelperMethods parseStringWithKey:@"fax" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.fax);
    obj.mail = [JSONEncodingHelperMethods parseStringWithKey:@"mail" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.mail);
    obj.street = [JSONEncodingHelperMethods parseStringWithKey:@"street" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.street);
    obj.city = [JSONEncodingHelperMethods parseStringWithKey:@"city" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.city);
    obj.postcode = [JSONEncodingHelperMethods parseStringWithKey:@"postcode" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.postcode);
    obj.isOpen = [JSONEncodingHelperMethods parseBoolWithKey:@"isOpen" fromJsonObject:jsonObj];
    obj.priority = [JSONEncodingHelperMethods parseIntegerWithKey:@"priority" fromJsonObject:jsonObj];
    obj.name = [JSONEncodingHelperMethods parseStringWithKey:@"name" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.name);
    
    obj.openingHours = [JSONEncodingHelperMethods parseObjectOfClass:[BAOpeningHours class] withKey:@"openingHours" fromJsonObject:jsonObj];
    EXPECT_OBJECT(BAOpeningHours, obj.openingHours);
    
    return obj;
}

- (NSDictionary *)toJSONObject
{
    EXPECT_OBJECT(NSString, self.phone);
    EXPECT_OBJECT(NSString, self.fax);
    EXPECT_OBJECT(NSString, self.mail);
    EXPECT_OBJECT(NSString, self.street);
    EXPECT_OBJECT(NSString, self.city);
    EXPECT_OBJECT(NSString, self.postcode);
    EXPECT_OBJECT(NSString, self.name);
    EXPECT_OBJECT(BAOpeningHours, self.openingHours);

    return @{
             @"phone" : self.phone,
             @"fax" : self.fax,
             @"mail" : self.mail,
             @"street" : self.street,
             @"city" : self.city,
             @"postcode" : self.postcode,
             @"isOpen" : [NSNumber numberWithBool:self.isOpen],
             @"priority" : [NSNumber numberWithInteger:self.priority],
             @"name" : self.name,
             @"openingHours" : self.openingHours
             };
}

@end
